﻿Imports CrystalDecisions.CrystalReports.Engine
''' <summary>
''' 銷售分析（銷售訂單）
''' </summary>生成採購申請單
''' songrenhua 2009-07-21
''' <remarks></remarks>
Public Class Frm_SALSCAnalyse


    Implements IDServer.IDServer.IDServer
    Private WithEvents MainForm As Frm_MainForm
    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp
    Private sql As String = String.Empty
    Private DS As DataSet
    Private DSet As DataSet
    Private DSet1 As DataSet
    Private FindTure As Boolean = False
    '單據ID、申請單號
    Private intID As Integer
    Private strFNum As String
    Private intDeptID As Integer
    Private intEmployID As Integer

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

#Region "Interface"

    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd

    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel

    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete

    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit

    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave

    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function
#End Region

    Private Sub StoreHouseLoad()
        Try
            sql = "SELECT DISTINCT SHOPNO,B.FSHORTNAME FROM SAL_SALEORDEA A "
            sql += "LEFT JOIN  BSC_STOREHOUSE B ON A.SHOPNO = B.FCODE  WHERE  shopno IS NOT null "
            DS = Exec(sql, E_ExecType.DataSet)
            Me.CBStoreHouseLoad.DataSource = DS.Tables(0)
            Me.CBStoreHouseLoad.DisplayMember = "FShortName"
            Me.CBStoreHouseLoad.ValueMember = "ShopNo"
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

    End Sub

    Private Sub DeptLoad()
        Try
            sql = "SELECT ID,fCode,fCName FROM BSC_DEPT WHERE fDefine=1 ORDER BY fCName "
            DSet = Exec(sql, E_ExecType.DataSet)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub EmployLoad()
        Try
            sql = "SELECT ID,fCode,fCName FROM BSC_Employee ORDER BY fCName "
            DSet1 = Exec(sql, E_ExecType.DataSet)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

    End Sub

    Private Sub Frm_SALSCAnalyse_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        StoreHouseLoad()
        DeptLoad()
        EmployLoad()
        Me.CBStoreHouseLoad.SelectedIndex = -1
        SelectByDept(False)
    End Sub

    Private Sub BtnTJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTJ.Click
        If Me.CheckBox1.Checked = True Then
            SelectByDept(True)
        Else
            SelectDT(True)
        End If
    End Sub

    Private Sub SelectDT(ByVal B As Boolean)

        Try
            FindTure = B
            sql = "   SELECT  convert(bit,0) as isSelected, '' as SHOPNO,Replace(FGOODSBARCODE,'*','') as FGOODSBARCODE," & vbCrLf
            sql += "  C.ENNAME,SUM(FSUMCOUNT) AS QTY,isnull(h.GOODSAMOUNT,0) as GOODSAMOUNT,MINNUM as MinAmount,'' as  Amount,C.PRICE,C.CNNAME" & vbCrLf
            sql += " FROM DBO.SAL_SALEORDEA A " & vbCrLf
            sql += " LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO = B.FSALEORDENO" & vbCrLf
            sql += " INNER JOIN BSC_GOODS C ON B.FGOODSBARCODE = C.BARCODE" & vbCrLf
            sql += " LEFT JOIN  BSC_STOREHOUSE D ON A.SHOPNO = D.FCODE" & vbCrLf
            'sql += " LEFT JOIN BSC_COLORDEFINE E ON C.COLOR= E.COLORCODE " & vbCrLf
            'sql += " LEFT JOIN (" & vbCrLf
            'sql += " SELECT * FROM DBO.BSC_OTHERDEFINEB WHERE " & vbCrLf
            'sql += " ITEMNO = (SELECT ID FROM BSC_OTHERDEFINEA WHERE ITEMCODE= 'UNITDEFIN')" & vbCrLf
            'sql += " )F ON C.UNIT= F.LISTCODE" & vbCrLf
            'sql += " LEFT JOIN BSC_SIZEDEFINE G ON C.SPEC = G.SIZECODE " & vbCrLf
            sql += "  left join (SELECT BARCODE,SUM(GOODSAMOUNT) AS GOODSAMOUNT FROM" & vbCrLf
            sql += "   V_VISUALSTOREQUERY   GROUP BY BARCODE) h" & vbCrLf
            sql += "  on c.BARCODE=h.BARCODE" & vbCrLf
            sql += ""

            sql += " WHERE  isnull(FLAG,'') <> '1'  AND  FSUMCOUNT>0" & vbCrLf

            If FindTure = False Then
                sql += " AND 1<>1 " & vbCrLf
            Else
                sql += " AND FOPERATEDATE BETWEEN '" & Me.DateTimePicker3.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker4.Value.ToString("yyyy-MM-dd") & "'" & vbCrLf
            End If
            sql += " GROUP BY FGOODSBARCODE,C.CNNAME,C.ENNAME,GOODSAMOUNT,PRICE,MINNUM" & vbCrLf
            'sql += " COLORCNAME,SIZESNAME,LISTA" & vbCrLf
            sql += " ORDER BY FGOODSBARCODE" & vbCrLf
            DS = Exec(sql, E_ExecType.DataSet)
            If FindTure = False Then
            Else
                If DS.Tables(0).Rows.Count <= 0 Then
                    MessageBox.Show("沒有記錄可以查詢", "加朗軟件", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If

            Me.DataGridView1.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView1, Me.ReturnCaption(1))
            SetDGVStyle(Me.DataGridView1)
            Me.DataGridView1.Columns("SHOPNO").Visible = False



        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    ''' <summary>
    ''' 設置DGV格式
    ''' </summary>
    ''' <param name="DGV">傳入DGV</param>
    ''' <remarks></remarks>
    Private Sub SetDGVStyle(ByVal DGV As DataGridView)
        Try
            Me.DataGridView1.Columns("isSelected").Width = 45
            Me.DataGridView1.Columns("CNNAME").Width = 300
            Me.DataGridView1.Columns("Amount").CellTemplate.Style.BackColor = Color.LightYellow
            Me.DataGridView1.Columns("SHOPNO").ReadOnly = True
            Me.DataGridView1.Columns("FGOODSBARCODE").ReadOnly = True
            Me.DataGridView1.Columns("ENNAME").ReadOnly = True
            Me.DataGridView1.Columns("QTY").ReadOnly = True
            Me.DataGridView1.Columns("GOODSAMOUNT").ReadOnly = True
            Me.DataGridView1.Columns("PRICE").ReadOnly = True
            Me.DataGridView1.Columns("CNNAME").ReadOnly = True
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Try
    End Sub

    Private Sub SelectByDept(ByVal B As Boolean)

        Try
            FindTure = B
            sql = " SELECT  convert(bit,0) as isSelected, D.FSHORTNAME AS SHOPNO,Replace(FGOODSBARCODE,'*','') as FGOODSBARCODE," & vbCrLf
            'sql += " E.COLORCNAME AS COLOR,G.SIZESNAME AS  SPEC,F.LISTA AS UNIT,"
            sql += " C.ENNAME,SUM(FSUMCOUNT) AS QTY,isnull(h.GOODSAMOUNT,0) as GOODSAMOUNT,isnull(i.MinAmount,0.00) as MinAmount,'' as  Amount,C.PRICE, C.CNNAME" & vbCrLf
            sql += " FROM DBO.SAL_SALEORDEA A " & vbCrLf
            sql += " LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO = B.FSALEORDENO" & vbCrLf
            sql += " INNER JOIN BSC_GOODS C ON B.FGOODSBARCODE = C.BARCODE" & vbCrLf
            sql += " LEFT JOIN  BSC_STOREHOUSE D ON A.SHOPNO = D.FCODE" & vbCrLf
            'sql += " LEFT JOIN BSC_COLORDEFINE E ON C.COLOR= E.COLORCODE " & vbCrLf
            'sql += " LEFT JOIN (" & vbCrLf
            'sql += " SELECT * FROM DBO.BSC_OTHERDEFINEB WHERE " & vbCrLf
            'sql += " ITEMNO = (SELECT ID FROM BSC_OTHERDEFINEA WHERE ITEMCODE= 'UNITDEFIN')" & vbCrLf
            'sql += " )F ON C.UNIT= F.LISTCODE" & vbCrLf
            'sql += " LEFT JOIN BSC_SIZEDEFINE G ON C.SPEC = G.SIZECODE " & vbCrLf
            sql += " left join (SELECT STOREHOUSE,BARCODE,SUM(GOODSAMOUNT) AS GOODSAMOUNT FROM" & vbCrLf
            sql += "  V_VISUALSTOREQUERY   GROUP BY STOREHOUSE,BARCODE) h" & vbCrLf
            sql += " on c.BARCODE=h.BARCODE and h.STOREHOUSE = A.SHOPNO " & vbCrLf
            sql += " LEFT JOIN GOODS_AMOUNT I ON C.BARCODE = I.BARCODE AND  I.STOREHOUSE = A.SHOPNO " & vbCrLf
            sql += " WHERE  isnull(FLAG,'') <> '1'  AND  FSUMCOUNT>0" & vbCrLf

            If FindTure = False Then
                sql += " AND 1<>1 " & vbCrLf
            Else
                sql += " AND FOPERATEDATE BETWEEN '" & Me.DateTimePicker3.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker4.Value.ToString("yyyy-MM-dd") & "'" & vbCrLf
                If Me.CheckBox1.Checked = True Then
                    If Me.CBStoreHouseLoad.Text.Length > 0 Then
                        sql += " AND SHOPNO = '" & Me.CBStoreHouseLoad.SelectedValue & "' " & vbCrLf
                    End If
                End If

            End If
            sql += " GROUP BY FSHORTNAME,FGOODSBARCODE,C.CNNAME,C.ENNAME,GOODSAMOUNT,PRICE,MinAmount" & vbCrLf
            'sql += " COLORCNAME,SIZESNAME,LISTA" & vbCrLf
            sql += " ORDER BY FSHORTNAME" & vbCrLf
            DS = Exec(sql, E_ExecType.DataSet)
            If FindTure = False Then
            Else
                If DS.Tables(0).Rows.Count <= 0 Then
                    MessageBox.Show("沒有記錄可以查詢", "加朗軟件", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If

            Me.DataGridView1.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView1, Me.ReturnCaption(1))
            SetDGVStyle(Me.DataGridView1)
            Me.DataGridView1.Columns("SHOPNO").Visible = True


        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Function ReturnCaption(ByVal index As Integer) As Hashtable
        Try
            Dim Hash As New Hashtable
            Select Case index
                Case 1
                    Hash.Add("isSelected", "選擇")
                    Hash.Add("SHOPNO", "門店")
                    Hash.Add("FGOODSBARCODE", "貨品條碼")
                    Hash.Add("ENNAME", "英文名")
                    Hash.Add("QTY", "銷售數量")
                    Hash.Add("GOODSAMOUNT", "庫存數量")
                    Hash.Add("MinAmount", "最低庫存量")
                    Hash.Add("Amount", "採購量")
                    Hash.Add("PRICE", "價格")
                    'Hash.Add("COLOR", "顏色")
                    'Hash.Add("SPEC", "規格")
                    'Hash.Add("UNIT", "單位")
                    Hash.Add("SHORTNAME", "簡稱")
                    Hash.Add("CNNAME", "中文名")
                Case 2
                    Hash.Add("isSelected", "選擇")
                    Hash.Add("FGOODSBARCODE", "貨品條碼")
                    Hash.Add("ENNAME", "英文名")
                    Hash.Add("QTY", "銷售數量")
                    Hash.Add("GOODSAMOUNT", "庫存數量")
                    Hash.Add("MinAmount", "最低庫存量")
                    Hash.Add("Amount", "採購量")
                    Hash.Add("PRICE", "價格")
                    'Hash.Add("COLOR", "顏色")
                    'Hash.Add("SPEC", "規格")
                    'Hash.Add("UNIT", "單位")
                    Hash.Add("SHORTNAME", "簡稱")
                    Hash.Add("CNNAME", "中文名")

            End Select
            Return Hash
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Try
    End Function

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If Me.CheckBox1.Checked = True Then
            Me.CBStoreHouseLoad.Enabled = True
        Else
            Me.CBStoreHouseLoad.Enabled = False
        End If
    End Sub

    ''' <summary>
    ''' 生成採購申請單
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub BtnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCreate.Click
        Try
            If Me.DataGridView1.Rows.Count <= 0 Then
                Exit Sub
            End If

            GetRequestID()

            '請購單的ID與單號
            Dim ID As Integer = intID
            Dim FNum As String = strFNum
            'PUR_RequestA中總價格
            Dim FAmount As Double
            'PUR_RequestB裱中的序號
            Dim SN As Integer = 1


            '找出操作者的ID
            Dim Rows() As DataRow = DSet1.Tables(0).Select("fCode='" & PubUserName & "'")
            For Each mRow As DataRow In Rows
                intEmployID = mRow.Item("ID")
            Next

            Dim FDate As String   '申請日期
            FDate = Now.ToString("yyyy-MM-dd")

            '向PUR_RequestA表中插入記錄
            sql = "INSERT INTO PUR_RequestA (ID, FNum, FDate, FDept, FEmployee," & vbCrLf
            sql += " FAmount, FRemark, BillstatusID, BulidDate, LastUpdateDate," & vbCrLf
            sql += " BulidComputer, LastUpdateComputer, BulidBy, LastUpdateBy) VALUES (" & vbCrLf
            sql += ID & ",'" & FNum & "','" & FDate & "'," & intDeptID & "," & intEmployID & "," & vbCrLf
            sql += FAmount & ",'由銷售分析生成','A',convert(varchar(19),getdate(),120),convert(varchar(19),getdate(),120)," & vbCrLf
            sql += "host_name(),host_name()," & intEmployID & "," & intEmployID & ");" & vbCrLf

            Dim DT As DataTable
            DT = CType(Me.DataGridView1.DataSource, DataTable)
            Dim ISSELECTEDRows() As DataRow = DT.Select("ISSELECTED= TRUE")
            If ISSELECTEDRows.Length <= 0 Then
                MessageBox.Show("沒有選中要生成採購申請的貨品", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
            For i As Int32 = 0 To ISSELECTEDRows.Length - 1

                Dim FGOODSBARCODE As String = ISSELECTEDRows(i)("FGOODSBARCODE").ToString()

                Dim GoodsBarCode As String = "*" + FGOODSBARCODE + "*"

                '先判斷選中的記錄中採購量是否為空
                '如果為空 CType(ISSELECTEDRows(i)("Amount").ToString(), Integer) 會轉換錯誤
                Try
                    If ISSELECTEDRows(i)("Amount").ToString() = "" Then
                        MessageBox.Show("請填寫 " & FGOODSBARCODE & "的採購申請數量", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Exit Sub
                    End If
                Catch ex As Exception
                    MessageBox.Show("請正確填寫 " & FGOODSBARCODE & "的採購申請的數量", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                End Try

                Dim ENNAME As String = ISSELECTEDRows(i)("ENNAME").ToString()
                '需求數量
                Dim FNeedQty As Integer = CType(ISSELECTEDRows(i)("QTY").ToString(), Integer)
                '庫存數量
                Dim FStoreQty As Integer = CType(ISSELECTEDRows(i)("GOODSAMOUNT").ToString(), Integer)
                '採購數量
                Dim FPOQty As Integer = CType(ISSELECTEDRows(i)("Amount").ToString(), Integer)
                '最低採購數量
                Dim FMinPOQty As Integer = CType(ISSELECTEDRows(i)("MinAmount").ToString(), Integer)
                '價格，作參考
                Dim FPrice As Double = CType(ISSELECTEDRows(i)("PRICE").ToString(), Double)
                '向PUR_RequestB表中循環插入記錄
                sql += " INSERT INTO PUR_RequestB (ID, SN, Barcode, FNeedQty, FStoreQty," & vbCrLf
                sql += " FPOQty,FMinPOQty,FPrice, DeliveryDate, FRemark) VALUES ( " & vbCrLf
                sql += ID & ",'" & SN & "','" & GoodsBarCode & "'," & FNeedQty & "," & FStoreQty & "," & vbCrLf
                sql += FPOQty & "," & FMinPOQty & "," & FPrice & ",'" & FDate & "','由銷售分析生成');" & vbCrLf

                SN = SN + 1

            Next
            Try
                Exec(sql, E_ExecType.ExecuteNonQuery)
            Catch ex As Exception
                Exit Sub
            End Try

            MessageBox.Show("生成採購申請單號:" & FNum & "", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    ''' <summary>
    ''' 獲取申請單新的ID和FNum
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetRequestID()
        Try
            Dim sql As String
            Dim dsA As New DataSet

            '找出操作者的部門ID
            Dim Rows() As DataRow = DSet.Tables(0).Select("fCode='" & PubCompanyCode & "'")
            For Each mRow As DataRow In Rows
                intDeptID = mRow.Item("ID")
            Next
            Dim DeptID As Integer = intDeptID
            Dim strID As String
            Dim FDate As String
            FDate = Now.Year.ToString + "/" + Now.Month.ToString + "/" + Now.Day.ToString

            sql = "select dbo.GetRequestID (" & DeptID & ",'" & FDate & "')"
            dsA = ReturnDataset(sql)
            strID = GetValue(sql)

            '請購單號
            strFNum = strID.Split(",")(0)
            '請購單ID
            intID = CInt(strID.Split(",")(1))


        Catch ex As Exception
            MsgBox("setDgv：" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub


    Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DataGridView1_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        Try
            Dim mDT As DataTable = CType(Me.DataGridView1.DataSource, DataTable)
            If Me.CheckBox2.Checked = True Then
                If mDT.Rows.Count > 0 Then
                    For Each row As DataRow In mDT.Rows
                        row("isselected") = True
                    Next
                End If
            End If
            If Me.CheckBox2.Checked = False Then
                If mDT.Rows.Count > 0 Then
                    For Each row As DataRow In mDT.Rows
                        row("isselected") = False
                    Next
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        Try
            Dim Amount As Integer
            If e.ColumnIndex = 7 Then
                Dim DT As DataTable = CType(Me.DataGridView1.DataSource, DataTable)
                If DT.Rows.Count > 0 Then
                    Try
                        Amount = CType(Me.DataGridView1.CurrentRow.Cells("Amount").Value, Integer) & ""
                    Catch ex As Exception
                        MessageBox.Show("請輸入整數", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        'Me.DataGridView1.CurrentRow.Cells("amount").Value = ""
                        Exit Sub
                    End Try
                    If Amount >= 1 Then
                        Me.DataGridView1.CurrentRow.Cells("isselected").Value = True
                    Else
                        Me.DataGridView1.CurrentRow.Cells("isselected").Value = False
                    End If
                    If Me.DataGridView1.CurrentRow.Cells("isselected").Value = True Then
                        Me.DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.LightSkyBlue
                    Else
                        Me.DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.White
                    End If
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
End Class
